package map;

import java.util.ArrayList;
import java.util.HashSet;

public class L349 {
    public int[] intersection(int[] nums1, int[] nums2) {
        HashSet<Integer> set1 = new HashSet<>();
        HashSet<Integer> set2 = new HashSet<>();
        for (int num : nums1) {
            set1.add(num);
        }
        for (int num : nums2) {
            set2.add(num);
        }
        ArrayList<Integer> list = new ArrayList<>();
        for (int num1:set1){
            if (set2.contains(num1)){
                list.add(num1);
            }
        }
        int[] array = list.stream().mapToInt(Integer::intValue).toArray();
        return array;
    }
}
